package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.SignState;
import cn.wolfcode.trip.base.domain.UserIntegral;
import cn.wolfcode.trip.base.domain.UserOrder;
import cn.wolfcode.trip.base.mapper.SignStateMapper;
import cn.wolfcode.trip.base.mapper.UserIntegralMapper;
import cn.wolfcode.trip.base.mapper.UserOrderMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IUserIntegralService;
import cn.wolfcode.trip.base.service.IUserOrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class UserIntegralServiceImpl implements IUserIntegralService {

    @Autowired
    private UserIntegralMapper userIntegralMapper;
    @Autowired
    private SignStateMapper signStateMapper;

    @Override
    public UserIntegral selectByIndentId(Long id) {
        return userIntegralMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(Long id,Integer integral) {
        SignState signState = new SignState();
        signState.setId(id);
        UserIntegral userIntegral = userIntegralMapper.selectByPrimaryKey(id);

        userIntegralMapper.updata(userIntegral.getId(),userIntegral.getIntegral() + integral);
        //修改状态
        if (integral == 10000){
            signState.setWeek(1);
        }else if (integral == 20000){
            signState.setHalfMonth(1);
        }else if (integral == 50000){
            signState.setMonth(1);
        }
        signStateMapper.update(signState.getId(),signState.getWeek(),signState.getHalfMonth(),signState.getMonth());

    }
}

